package it.a.devil;

import it.a.devil.Main.BaseConverter;
import it.a.devil.Main.SimpleConvert;
import junit.framework.TestCase;
import cn.edu.hust.cm.lib.BinFileWrapper;

public class MainTest extends TestCase {

	private Main.SimpleConvert mSimpleConvert;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		mSimpleConvert = new SimpleConvert();
	}

	public void testSimpleConvert() throws Exception {

		byte[] data = { 4, 4, 1, -8 };
		byte[] buf = new byte[1024];
		int n = mSimpleConvert
				.convert(data, 0, data.length, buf, 0, buf.length);

		assertEquals(2 * data.length, n);

		byte[] res = { 4, 1, 4, 0, 1, 4, -8, 5 };
		for (int i = 0; i < res.length; i += 2) {
			assertEquals(res[i], data[i / 2]);
		}
	}

	public void testBaseConverter() throws Exception {
		BaseConverter bc = new BaseConverter(mSimpleConvert, "c:\\ui2.py",
				"c:\\ui2.py.test");
		bc.convert();

		BinFileWrapper bfw = new BinFileWrapper("c:\\ui2.py.test");
		for (String string : bfw) {
			System.out.println(string);
		}
		System.out.println();
		System.out.println();

		bc.deconvert();

	}
}
